package com.jay.io.clazz;

import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.IOException;

public class CharArrayReaderWriterCls {
	public static void main(String[] args) {
		try {

			CharArrayWriter charArrayWriter = new CharArrayWriter();
			char[] array = new char[] { 'a', '晕', 'c', '|' };
			charArrayWriter.write(array);

			charArrayWriter.close();

			// 显示字符内容
			array = charArrayWriter.toCharArray();
			for (int i = 0; i < array.length; i++) {
				System.out.print(array[i]);
			}
			System.out.println();

			array[0] = 'b';
			array[1] = '倒';

			// 将字符数组内容存回文件
			CharArrayReader charArrayReader = new CharArrayReader(array);

			char[] tmp = new char[1];
			while (charArrayReader.read(tmp) != -1) {
				System.out.print(tmp);
			}

			charArrayReader.close();
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("请指定文件名！");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
